package player.ui.tree;

import java.awt.Component;
import java.io.File;

import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.filechooser.FileSystemView;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;

import player.Tools;

public class FileSystemTreeRendererDialog extends DefaultTreeCellRenderer implements TreeCellRenderer {
	private static final long serialVersionUID = -5000688751762857407L;
	private FileSystemView fsv=FileSystemView.getFileSystemView();
	 

	   public FileSystemTreeRendererDialog() {
		   super();
	   }

	   public Component getTreeCellRendererComponent(JTree tree,
	         Object value, boolean sel, boolean expanded, boolean leaf,
	          int row, boolean hasFocus) {
	      if (!(value instanceof File)) {
	         return new JLabel("ss");
	      }
	      File file=(File) value;
	      Icon icon=Tools.getFileIcon(file);
	      
	      JLabel result = (JLabel) super.getTreeCellRendererComponent(tree,
	    		  fsv.getSystemDisplayName((File) value), sel, expanded, leaf, row, hasFocus);
			if (file != null) {
				if (icon == null) {
					icon = fsv.getSystemIcon(file);
				}
				result.setIcon(icon);
			}
	      return result;
	   }
	   
}